package com.arvato.wxwork.service.ncc;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.arvato.common.config_bean.WxworkConfig;
import com.arvato.common.https.HttpUtil;
import com.arvato.common.util.JsonUtil;
import com.arvato.common.util.MD5Util;
import com.arvato.minipro.bean.bean_dto.common.Query;
import com.arvato.wxwork.bean.bean_do.ncc.WxworkTaskDo;
import com.arvato.wxwork.bean.bean_vo.ncc.WxworkTaskVo;
import com.arvato.wxwork.mapper.ncc.WxworkTaskMapper;


@Service
@Transactional
public class WxworkNccTaskService {
	
	private Logger logger = LoggerFactory.getLogger(WxworkNccTaskService.class);
	
	@Autowired
	private WxworkTaskMapper wxworkTaskMapper;
	
	@Autowired
	private JsonUtil jsonUtil;
	
	public Map<String, Object> getTaskList(String dateStr, String campaignID, int pageIndex, int pageSize){
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("Date", dateStr);
		paramMap.put("CampaignID", campaignID);
		paramMap.put("PageIndex", pageIndex);
		paramMap.put("PageSize", pageSize);
		String url = WxworkConfig.NccAsync;
		String token = MD5Util.md5("NccAsync#ad2*8jfdsas(^@");
		paramMap.put("token", token);
		logger.info("NccAsync" + ":" + url + "请求参数:" + jsonUtil.obj2String(paramMap));
		long startTime = System.currentTimeMillis();
		String responseStr = HttpUtil.doPostJsonData(url,paramMap);
		long endTime = System.currentTimeMillis();
		logger.info("NccAsync" + "时间:" + (endTime - startTime));
		logger.info("NccAsync" + "请求结果:" + responseStr);
		Map<String, Object> resultMap = jsonUtil.str2Map(responseStr);
		System.out.println(jsonUtil.obj2String(resultMap));
		return resultMap;
	}
  
	public List<WxworkTaskVo> taskListByStaffId(Query query) {
		return 	wxworkTaskMapper.taskListByStaffId(query);
	}
	
	public int update(WxworkTaskDo wxworkTaskDo) {
		return 	wxworkTaskMapper.update(wxworkTaskDo);
	}
}
